package suites.integration {
	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.assertFalse;
	import org.flexunit.asserts.assertNotNull;
	import org.flexunit.asserts.assertTrue;
	import org.splink.library.queue.QEvent;
	import org.splink.resource.IResourceProvider;
	import org.splink.resource.ResourceProvider;

	/**
	 * <code>FontTest</code> assumes that there is a arial.swf within the sample/fonts folder
	 * which contains the arial font
	 * 
	 * @author Max Kugland
	 */
	public class FontTest extends AbstractIntegrationTest {
		private static const TYPE_TEXT : String = "text";		private static const TYPE_SYSTEM : String = "system";

		[Test (async)]
		public function singleFontDefaultLocale() : void {
			handleAsync(1000);
			
			var xml : XML = <resourcebundles defaultLocale="de_DE">
								<resourcebundle locale="de_DE">
									<fonts path="../sample/fonts/">
										<font id="Arial" type="text" src="arial.swf" filesize="21858" />
										<font id="Verdana" type="system" isSystemFont="true" filesize="0" />
									</fonts>
								</resourcebundle>
							</resourcebundles>;
			
			createProcessor(xml, function(e : QEvent) : void {
				assertProvider(ResourceProvider.instance());
			}).start();
		}

		[Test (async)]
		public function singleFontSelectedLocale() : void {
			handleAsync(1000);
			
			var xml : XML = <resourcebundles defaultLocale="de_DE">
								<resourcebundle locale="de_DE">
									<fonts path="../sample/fonts/">
										<font id="Arial" type="text" src="arial.swf" filesize="21858" />
										<font id="Verdana" type="system" isSystemFont="true" filesize="0" />
									</fonts>
								</resourcebundle>
								<resourcebundle locale="en_EN">
									<fonts path="../sample/fonts/">
										<font id="Arial" type="text" src="arial.swf" filesize="21858" />
										<font id="Verdana" type="system" isSystemFont="true" filesize="0" />
									</fonts>
								</resourcebundle>
							</resourcebundles>;
			
			createProcessor(xml, function(e : QEvent) : void {
				assertProvider(ResourceProvider.instance());
			}, "en_EN").start();
		}

		public static function assertProvider(p : IResourceProvider) : void {
			assertNotNull(p.getFontDataByType(TYPE_TEXT));
			assertNotNull(p.getFontDataByType(TYPE_SYSTEM));
				
			assertFalse(p.getFontDataByType(TYPE_TEXT).isSystemFont);
			assertTrue(p.getFontDataByType(TYPE_SYSTEM).isSystemFont);
				
			assertEquals("Arial", p.getFontDataByType(TYPE_TEXT).id);
			assertEquals("Verdana", p.getFontDataByType(TYPE_SYSTEM).id);
				
			assertEquals(0, p.getFontDataByType(TYPE_TEXT).xOffset);
			assertEquals(0, p.getFontDataByType(TYPE_TEXT).yOffset);
			assertEquals(0, p.getFontDataByType(TYPE_TEXT).sizeOffset);
				
			assertEquals(0, p.getFontDataByType(TYPE_SYSTEM).xOffset);
			assertEquals(0, p.getFontDataByType(TYPE_SYSTEM).yOffset);
			assertEquals(0, p.getFontDataByType(TYPE_SYSTEM).sizeOffset);
		}
	}
}
